package com.bpms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bpms.common.VO;
import com.bpms.esb.SV;
import com.service.util.MD5DigitVerifyUtil;
import com.zk.atm.utils.ConstantsAtmp;
import com.zk.atm.utils.JsonUtil;

@SuppressWarnings("serial")
public class GateWayServlet extends BaseServlet {

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		//返回结果集:VO，里面包括3个主要参数，ret,message,data; 
		String json="";
	try {
		VO args = new VO();
		args=getVo(request, response);
		boolean is_pass_md5_digit=MD5DigitVerifyUtil.checkMD5DigitVerify(args);
		if(is_pass_md5_digit==false){
			VO vo=new VO();
			vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "1");
			vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "数字签名校验失败!您的访问被服务器拒绝,请与管理员联系!");
			String json_str=JsonUtil.getJsonObjectByBpmVo(vo);
			response.getWriter().write(json_str);
			return ;
		}
		String method = args.getAttr("m") ;
		String r = args.getAttr("r") ;
		//String query_all = args.getAttr("QUERY_ALL") ;
		System.out.println("method="+method+",r="+r);//+",query_all="+query_all);
		//IService
		VO vo = SV.g(method, args);
			//设备监控列表 
			if(method.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_ACTION_METHOD)){
				 status_list(request, response);
				 return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_ACTION_METHOD)){
				 device_list(request, response);//设备列表
				 return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_ACTION_SAVE_METHOD)){
				super.device_save(request, response);//设备保存
				return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_ACTION_DEL_METHOD)){
				super.device_del(request, response);//设备删除
				return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_LIST)){
				super.device_type_list(request, response);//设备类型列表
				return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_SAVE)){
				super.device_type_save(request, response);//设备类型保存
				return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_DEL)){
				super.device_type_del(request, response);//设备类型删除
				return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_CHILDREN_LIST)){
				super.device_type_children_list(request, response);//设备子类型列表
				return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_CHILDREN_SAVE)){
				super.device_type_children_save(request, response);//设备子类型保存
				return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_CHILDREN_DEL)){
				super.device_type_children_del(request, response);//设备子类型删除
				return;
			}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_TRADE_EXPORT)){//导出tradeList
				super.export_trade_list(request, response);
				return;
			}
			else{
			   json = JsonUtil.getJsonObjectByBpmVo(vo);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		PrintWriter out=response.getWriter();
		out.write(json);
		out.flush();
		out.close();
		return;
	}
	
	

}
